package com.uneed;

import java.util.ArrayList;

import com.uneed.adapter.BasicAdapter;
import com.uneed.api.Category;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    protected ArrayList<? extends Parcelable> dlgListItems;    
    protected Parcelable dlgListSelectedItem;
    
    protected class ListAdapter extends BasicAdapter
    {
      LayoutInflater layoutInflater = getLayoutInflater();

      public ListAdapter()
      {
      }

      public int getCount()
      {
        if (dlgListItems == null);
        for (int i = 0; ; i = dlgListItems.size())
          return i;
      }

      public Parcelable getItem(int paramInt)
      {
        if ((dlgListItems == null) || (paramInt >= dlgListItems.size()));
        for (Parcelable localParcelable = null; ; localParcelable = (Parcelable)dlgListItems.get(paramInt))
          return localParcelable;
      }

      public long getItemId(int paramInt)
      {
        Parcelable localParcelable = getItem(paramInt);
        long l;
        if (localParcelable == null) {
          l = 0L;
        } else {
          if (localParcelable instanceof Category) 
            l = ((Category)localParcelable).id();
          else l = localParcelable.hashCode();
      }
        return l;
    }

      public int getItemViewType(int paramInt)
      {
        return 0;
      }

      public String getName(int paramInt)
      {
        Parcelable localParcelable = getItem(paramInt);
        if (localParcelable == null);
        String str = "";      
        if (localParcelable instanceof Category)
           str = ((Category)localParcelable).name();
        else         str = localParcelable.toString();
        return str;
      }
      
      @Override
      public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
      {
          if ((paramView == null) || (paramView.getTag() != this))
          {
              paramView = this.layoutInflater.inflate(R.layout.dialog_list_item, paramViewGroup);
              paramView.setTag(this);
          }
          ((TextView)paramView.findViewById(16908308)).setText(getName(paramInt));
          View localView = paramView.findViewById(R.id.ic_checked);
          if (getItem(paramInt).equals(dlgListSelectedItem)) {
              localView.setVisibility(View.VISIBLE);
          } else {
              localView.setVisibility(View.VISIBLE);
          }
          return paramView;
          }
      }

      public int getViewTypeCount()
      {
        return 1;
      }

      public boolean hasStableIds()
      {
        return true;
      }

    }

    
